@using CodeBuilder
@using CodeBuilder.Models.TemplateModels
@inherits RazorEngine.Templating.TemplateBase<CodeBuilder.Models.TemplateModels.DtoFileModel>

<template>
    <el-form ref="editForm"
             label-width="120px"
             :model="entity"
             :rules="formRule">
        
        @foreach (ClassProperty classProperty in Model.ClassPropertys)
        {
            if (classProperty.Name == "TenantId")
            {
                continue;
            }

            <el-form-item :label="L('@(classProperty.Name)')"
                          prop="@(classProperty.Name.FirstCharToLower())">
                <el-input v-model="entity.@(classProperty.Name.FirstCharToLower())"
                          :maxlength="32"
                          :minlength="2"/>
            </el-form-item>
        }

    </el-form>
</template>
<script>
    export default {
        name: 'CreateOrEdit',
        props: {
            entity: {
                type: Object,
                default: () => { return {} }
            }
        },
        data() {
            return {
                editEntity: {},
                formRule: {
                    @foreach (ClassProperty classProperty in Model.ClassPropertys)
                    {
                        if (classProperty.Name == "TenantId")
                        {
                            continue;
                        }
                        <text>
                        @(classProperty.Name.FirstCharToLower()): [{ required: true, message: this.L('FieldIsRequired', undefined, this.L('@(classProperty.Name)')), trigger: 'blur' }],
                        </text>
                    }
                    a: []
                }
            }
        },
        watch: {
            entity(val) {
                // if (val.id) {
                //   for (var e in this.entity) {
                //     this.entity[e] = null
                //   }
                // }
            }
        },
        created() {
        },
        methods: {
            clearValidate() {
                this.$refs.editForm.clearValidate()
            },
            validate(cb) {
                this.$refs.editForm.validate(cb)
            }
        }
    }
</script>
